import { Configuration, App, Inject } from '@midwayjs/core';
import * as koa from '@midwayjs/koa';
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
import { join } from 'path';
import { ReportMiddleware } from './middleware/report.middleware';
import * as orm from '@midwayjs/typeorm';
import { StatusService } from './service/status.service';
import { UserService } from './service/user.service';
import { DefaultErrorFilter } from './filter/default.filter';
import { FormatMiddleware } from './middleware/format.middleware';
import * as jwt from '@midwayjs/jwt';
import { JwtMiddleware } from './middleware/jwt.middleware';
import * as busboy from '@midwayjs/busboy';
import * as staticFile from '@midwayjs/static-file';
import * as crossDomain from '@midwayjs/cross-domain';
// import * as upload from '@midwayjs/upload';
@Configuration({
  imports: [
    koa,
    validate,
    orm,
    jwt,
    busboy,
    staticFile,
    crossDomain,
    // upload,
    {
      component: info,
      enabledEnvironment: ['local'],
    },
  ],
  importConfigs: [join(__dirname, './config')],
})
export class MainConfiguration {
  @App('koa')
  app: koa.Application;

  @Inject()
  statusService: StatusService;


  @Inject()
  userService: UserService;

  async onReady() {
    this.app.useFilter([DefaultErrorFilter]);
    this.app.useMiddleware([ReportMiddleware, JwtMiddleware, FormatMiddleware]);
    // await this.statusService.addDefaultStatus();
    // await this.userService.addUser({
    //   id: 0, name: 'root', email: 'root@qq.com', password: 'root@qq.com', status: 0,
    //   images: [],
    //   salt: null,
    // });
  }
}
